package com.yra.controller.mall;

import com.yra.domain.Product;
import com.yra.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: yrq
 * @Date: Create in 15:03 2019/12/12
 */
@Controller
@RequestMapping
public class MallProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping(value = "/product/detail/{productId}")
    public ModelAndView goToProduct(@PathVariable("productId") int productId, HttpServletRequest request){
        Product product = productService.productById(productId);
        request.setAttribute("product",product);
        return new ModelAndView("/mall/detail");
    }
}
